<script type="text/html" template>
        <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
        <link rel="stylesheet" href="{{ layui.setter.base }}style/css/maintain/Change-order.css">
        <link rel="stylesheet" href="{{ layui.setter.base }}style/autoComplete.css">
        <link rel="stylesheet" href="{{ layui.setter.base }}style/css/maintain/alert_new.css">
        <link rel="stylesheet" href="{{ layui.setter.base }}style/css/patrol/project_device_alert.css">
</script>
<div class="page-fluid hide">
    <div class="content layui-fluid leon-fluid" id="detail">
        <form action="" class="layui-form">
            <div class="layui-fluid">
                <div class="layui-title">报修信息</div>
                <ul class="layui-row layui-fluid">
                    <li class="layui-col-sm3 layui-col-md3">
                        <div>工单编号:<span name="fil01"></span></div>
                        <div>报修人：<span name="gen02"></span></div>
                    </li>
                    <li class="layui-col-sm3 layui-col-md3">
                        <div>紧急程度：
                            <span id="select-view"></span>
                        </div>
                        <div>报修人电话：<span name="gen08s"></span></div>
                    </li>
                    <li class="layui-col-sm3 layui-col-md3">
                        <div>工单名称：<span name="tcReqName"></span></div>
                        <div>报修时间：<span name="fil10"></span></div>
                    </li>
                    <li class="layui-col-sm3 layui-col-md3">
                        <div>工单类型：<span name="fil04">类型</span></div>
                    </li>
                </ul>
            </div>
            <div class="layui-fluid">
                <div class="layui-title">设备信息</div>
                <ul class="layui-row layui-fluid">
                    <li class="layui-col-sm3 layui-col-md3">
                        <div>设备编号:<span name="fil03"></span></div>
                        <div>设备型号:<span name="fii02"></span></div>
                    </li>
                    <li class="layui-col-sm3 layui-col-md3">
                        <div>设备类型:<span name="fic02"></span></div>
                        <div>设备位置:<span name="tcFiaPlace"></span></div>
                    </li>
                    <li class="layui-col-sm3 layui-col-md3">
                        <div>供应商:<span name="pmc081"></span></div>
                        <div>设备系列:<span name="tcSeriesName"></span></div>
                    </li>
                </ul>
            </div>
            <div class="layui-fluid">
                <div class="layui-title">故障信息</div>
                <ul class="layui-row layui-fluid layui-form">
                    <li class="layui-col-sm6 layui-col-md6">
                        <div>故障发生时间:<span name="fil12"></span></div>
                       <div id="view"></div>
                    </li>
                    
                    <li class="layui-col-sm6 layui-col-md6">
                        <div>
                            <div style="float:left; height: auto;">附件：</div>
                            <div style="margin-left: 30px; height: auto;" name="tcEamFiles" id="downloadFile"></div>
                        </div>
                    </li>
                    <li class="pd  layui-col-sm12 layui-col-md12 layui-form">
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">故障说明：</label>
                            <div class="layui-input-block">
                                <textarea name="fil21" readonly placeholder="故障说明" class="layui-textarea"></textarea>
                            </div>
                    </li>
                </ul>
            </div>
            <div class="layui-fluid">
                <div class="layui-title">处理信息</div>
                <ul class="layui-row layui-fluid " id="makeInfo">
                </ul>
            </div>

            <div class="layui-btn-containner layui-form-item">

            </div>
        </form>
    </div>
    <div class="content layui-fluid leon-fluid hide" id="add">
        <form class="layui-form">
            <div class="layui-fluid" id="gdInfo">
                <div class="layui-title">新增报修工单</div>
                <ul class="layui-row layui-fluid">
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box layui-form-item">
                            <label class="layui-form-label">工单编号:</label>
                            <div class="layui-input-block readOnly">
                                <input type="text" name="fil01" readonly required lay-verify="required" placeholder=""
                                    autocomplete="off" class="layui-input" style="border:0px">
                            </div>
                        </div>
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label">报修时间:</label>
                            <div class="layui-input-block readOnly">
                                <input type="text" name="fil10" readonly required lay-verify="required" placeholder=""
                                    autocomplete="off" class="layui-input" style="border:0px">
                            </div>
                        </div>
                    </li>
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label"><span
                                    style="font-size:18px;color:red;position:relative;display:inline-block;line-height:20px;vertical-align:middle;top:3px;">*</span>紧急程度:</label>
                            <div class="layui-input-block">
                                <input type="radio" name="fil06" value="0" title="正常">
                                <input type="radio" name="fil06" value="1" title="重要">
                                <input type="radio" name="fil06" value="2" title="紧急">
                                <!-- <select name="fil06" id="" lay-verify="required">
                                    <option value="0">正常</option>
                                    <option value="1">重要</option>
                                    <option value="2">紧急</option>      
                                </select> -->
                            </div>
                        </div>
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label">报修人:</label>
                            <div class="layui-input-block readOnly">
                                <input type="text" name="gen02" readonly required lay-verify="required" placeholder=""
                                    autocomplete="off" class="layui-input" style="border:0px">
                            </div>
                        </div>
                    </li>
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label"><span
                                    style="font-size:18px;color:red;position:relative;display:inline-block;line-height:20px;vertical-align:middle;top:3px;">*</span>工单名称:</label>
                            <div class="layui-input-block">
                                <input type="text" name="tcReqName" required lay-verify="required" placeholder=""
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label">联系人电话:</label>
                            <div class="layui-input-block readOnly">
                                <input type="text" name="gen08" readonly required lay-verify="required" placeholder=""
                                    autocomplete="off" class="layui-input" style="border:0px">
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="layui-fluid" id="sbInfo">
                <div class="layui-title">设备信息</div>
                <ul class="layui-row layui-fluid">
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label"><span
                                    style="font-size:18px;color:red;position:relative;display:inline-block;line-height:20px;vertical-align:middle;top:3px;">*</span>设备编号:</label>
                            <div class="layui-input-block completeWrap">
                                <input name="fil03" id="fil03" value="" autocomplete="off" class="layui-input" required
                                    lay-verify="required" />
                            </div>
                        </div>
                        <div class="input-box layui-form-item">
                            <label class="layui-form-label">设备系列:</label>
                            <div class="layui-input-block readOnly">
                                <span name="tcSeriesName" id="tcSeriesName"></span>
                            </div>
                        </div>
                    </li>
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label">设备类型:</label>
                            <div class="layui-input-block readOnly">
                                <span name="fic02" id="Equipment"></span>
                            </div>
                        </div>
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label">设备型号:</label>
                            <div class="layui-input-block readOnly">
                                <span name="fii02"></span>
                            </div>
                        </div>
                    </li>
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label">供应商:</label>
                            <div class="layui-input-block readOnly">
                                <span name="pmc081" id="pmc081"></span>
                            </div>
                        </div>
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label">设备位置:</label>
                            <div class="layui-input-block readOnly">
                                <span name="tcFiaPlace" id="tcFiaPlace"></span>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="layui-fluid">
                <div class="layui-title">故障信息</div>
                <ul class="layui-row layui-fluid ">
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label"><span
                                    style="font-size:18px;color:red;position:relative;display:inline-block;line-height:20px;vertical-align:middle;top:3px;">*</span>故障发生时间:</label>
                            <div class="layui-input-block">
                                <input type="text" name="fil12" id="happenTime" required lay-verify="required"
                                    placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </li>
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item">
                            <label class="layui-form-label"><span
                                    style="font-size:18px;color:red;position:relative;display:inline-block;line-height:20px;vertical-align:middle;top:3px;">*</span>是否停机:</label>
                            <div class="layui-input-block">
                                <!-- <select name="tcReqIsstop" lay-verify="required">
                                    <option value=""></option>
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select> -->
                                <input type="radio" name="tcReqIsstop" value="0" title="否">
                                <input type="radio" name="tcReqIsstop" value="1" title="是">
                            </div>
                        </div>
                    </li>
                    <li class="layui-col-sm4 layui-col-md4 layui-form">
                        <div class="input-box  layui-form-item updateFileWrap">
                            <label class="layui-form-label">附件:</label>
                            <div class="layui-input-block">
                                <div class="layui-upload-drag" id="updateFile">
                                    <p>点击上传，或将文件拖拽到此处</p>
                                    <div class="layui-upload-list layui-hide" id="uploadDemoView">
                                        <table class="layui-table" lay-size="sm">
                                            <thead>
                                                <tr>
                                                    <th>文件名</th>
                                                    <th>操作</th>
                                                </tr>
                                            </thead>
                                            <tbody id="demoList"></tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li class="pd  layui-col-sm12 layui-col-md12 layui-form">
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label"><span
                                    style="font-size:18px;color:red;position:relative;display:inline-block;line-height:20px;vertical-align:middle;top:3px;">*</span>故障说明:</label>
                            <div class="layui-input-block">
                                <textarea name="fil21" placeholder="故障说明" class="layui-textarea"
                                    lay-verify="required"></textarea>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="layui-btn-containner">
                <button type="button" class="btn1 layui-btn layui-btn-radius layui-btn-primary" lay-submit
                    lay-filter="saveEdit">提交</button>
                <!-- <button type="button" class="layui-btn layui-btn-radius layui-btn-primary" id="deleteCur">删除</button> -->
                <button type="button" class="btn3 cancel-btn layui-btn layui-btn-radius layui-btn-primary">取消</button>
            </div>
        </form>
    </div>
</div>
<script type="text/template" id="deviceType">
        <div class="alert-box">
            <div class="box-title">故障类型详情</div>
            <form class="form layui-form" id="gzType">
                <div class="layui-form-item">
                    <label class="layui-form-label">故障类型编号:</label>
                    <div class="layui-input-block">
                        <input name="tcBugCode" id="params" autocomplete="off" class="layui-input"
                                        required lay-verify="required" />
                        <input type="text" readonly name="tcBugId" id="tcBugId" style="display:none" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">故障类型:</label>
                    <div class="layui-input-block">
                        <input type="text" style="border: 0" readonly name="tcBugName"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">故障类型说明:</label>
                    <div class="layui-input-block">
                        <span name="tcBugDsc"></span>
                    </div>
                </div>
                <div class="footer layui-btn-container">
                    <button type="button" class="btn1 layui-btn layui-btn-radius layui-btn-primary" lay-submit lay-filter="alertConfirm">确定</button>
                    <button type="button" class="btn2 cancel-btn layui-btn layui-btn-radius layui-btn-primary">取消</button>
                </div>
            </form>
        </div>
    </script>
<script type="text/template" id="changeAlert">
    <div class="alert-box" id="zdAlert">
        <div class="box-title">转单</div>
        <form class="form layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">原接单人:</label>
                <div class="layui-input-block">
                    <span name="fiausername">{{ d.filusername }}</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新接单人：</label>
                <div class="layui-input-block">
                    <input name="filuser" id="filuser" style="display: none" readonly />
                    <input name="filuserText" id="filuserText" value="" autocomplete="off" class="layui-input"
                    required lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注：</label>
                <div class="layui-input-block">
                    <textarea name="fil07" placeholder="请输入内容" class="layui-textarea" id="text"></textarea>
                </div>
            </div>
            <div class="footer layui-btn-container">
                <button type="button" lay-submit lay-filter="zd" class="btn1 layui-btn layui-btn-radius layui-btn-primary">确定</button>
                <button type="button" class="btn2 cancel-btn layui-btn layui-btn-radius layui-btn-primary">取消</button>
            </div>
        </form>
    </div>
</script>
<script type="text/html" id="select">
    {{#  if(d.fil06 == '0'){ }}
        <span style="color:green">正常</span>
        {{#  } else if(d.fil06 == '1') { }}
        <span style="color:#ff4100">重要</span>
        {{#  } else if(d.fil06 == '2') { }}
        <span  style="color:red">紧急</span>
    {{#  } }}   
    </script>
<script type="text/html" id="list">
    <div class="input-box  layui-form-item" style="margin-top: 10px;margin-bottom: 10px;">
    <label class="layui-form-label"><span style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>故障预计维修时长：</label>
    <div class="layui-input-block">
    <input type="text" name="tcReqDuration" id="Time" required lay-verify="required"
        placeholder="" autocomplete="off" class="layui-input" style="display: inline-block;width:40px" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
        <span>小时</span>
        <button type="button"  class="layui-btn layui-btn-xs layui-btn-normal time_bc" style="margin-left: 10px;">保存</button>
    </div>
    </div>
</script>
<script type="text/html" id="list_one">
    <div class="input-box  layui-form-item" style="margin-top: 10px;margin-bottom: 10px;">
    <label class="layui-form-label">故障预计维修时长：</label>
    <div class="layui-input-block">
        {{#  if(d.tcReqDuration  != null){ }}
        <span style="display: inline-block;width:40px" id="Time">{{ d.tcReqDuration }}小时</span>
        {{#  } else { }}
        
        {{#  } }} 
    </div>
    </div>
</script>
<!-- 弹出层 -->
<script type="text/html" id="addDeviceTpl">
        <div class="leon-style-alert">
            <div class="layui-alert-box">
                <div class="layui-alert-title">
                <span class="layui-title-inner">选择设备</span>
                <span class="layui-title-screen">
                <div class="screen-btn">
                    <form class="layui-form" action="">
                        <input type="search" name="keyWord" class="search-blank-inner searchInput" placeholder="搜索" autocomplete="off"/>
                        <button type="button" lay-submit lay-filter="queryTableDeviceHeader" class="search-blank-icon"></button>
                    </form>
                </div>
                </span>
                </div>
                <div class="layui-content">
                <div class="con1 toggle-btn">
                    <span class="screen">
                    <i class="query-icon  layui-icon"></i>
                    <span class="query-inner">查询条件</span>
                    </span>
                    <i class="icon layui-icon layui-icon-down"></i>
                </div>
                <div class="con2 toggle-content">
                    <form action="" class="layui-form">
                    <label for="">设备编号:</label>
                    <input type="text" name="fia01" />
                    <label for="">设备类型:</label>
                    <input type="text" name="fic01" />
                    <label for="">设备型号:</label>
                    <input type="text" name="fii01" />
                    <button type="button" lay-submit lay-filter="queryTableDevice"
                        class="query layui-btn layui-btn-radius layui-btn-primary">
                        <span class="search-icon"></span>
                        <span class="btn-inner">查询</span>
                    </button>
                    </form>
                </div>
                <table class="layui-table" id="MachineCapacityTable"></table>
                </div>
                <div class="footer layui-btn-containner">
                <button class="btn1 layui-btn layui-btn-radius layui-btn-primary" lay-submit lay-filter="queryTableDevice2">确定</button>
                <button class="btn2 layui-btn layui-btn-radius layui-btn-primary">取消</button>
                </div>
            </div>
        </div>
</script>

<script>
    ! function () {
        var $ = layui.$;
        layui.use(['form', 'table', 'api', 'utill', 'admin', 'view', 'laydate', 'upload', 'laytpl'], function () { //此段代码必不可少
            var table = layui.table,
                setter = layui.setter,
                laytpl = layui.laytpl,
                api = layui.api,
                utill = layui.utill,
                form = layui.form,
                element = layui.element,
                laypage = layui.laypage,
                form = layui.form,
                laydate = layui.laydate,
                upload = layui.upload,
                view = layui.view,
                admin = layui.admin;
                $('#detail').find('[name="tcReqDsc"]').html();
            form.render();
            $('[data-jump="maintain/google"]').addClass('layui-this').attr('color', '#FFF');
            var status = {
                fil05: '',
                isGen01: '',
                flag: 0,
            }
            var _DATA = {
                _GET_STATUS: null,
                _GET_DETAIL: null,
                files: []
            }

            var detail = function () {
                utill.loading.show();

                // 获得详情信息
                view.req({
                    url: api.host + api.gzbx.FilFileWxSelectWxDetails,
                    type: 'POST',
                    data: {
                        id: utill.getQueryVariable('tcReqId')
                    }
                }).done(function (res) {
                    _DATA._GET_DETAIL = res;
                    if (res.code == "0") {
                        mergeResponse();
                    }
                    var data = res.data;
                    
                    laytpl($('#select').html()).render(data, function (html) {
                        $('#select-view').html(html);
                        var getDetailData = _DATA._GET_DETAIL.data;
                        view.req({
                            url: api.host + api.gzbx.getEmployeeLead,
                            type: 'POST',
                            contentType: 'application/json',
                            data: JSON.stringify({
                                fil01: utill.getQueryVariable('fil01'),
                                gen01: getDetailData.fil08 || '',
                            })
                        }).done(function (res) {
                            if(res.data.fil05 == 2){
                                laytpl($('#list').html()).render(data, function(html){
                                    $('#view').html(html);
                                });
                                $('#view').on('click','.time_bc',function(data){
                                   let val = $('[name="tcReqDuration"]').val();
                                   let fil01 = $('[name="fil01"]').val();
                                   if(val == ''){
                                       layer.open({
                                           content: '请输入故障预计维修时长!'
                                       })
                                   }else{
                                    admin.req({
                                        url: api.host + '/fil/setIsUnPln.json',
                                        type: "get",
                                        data: {tcReqDuration: val,fil01:fil01},
                                        dataType: 'json',
                                        contentType: 'application/json',
                                        success: function (res) {
                                            layer.open({
                                                content: res.message
                                            });
                                        }
                                    })
                                   }
                                });
                            }else if(res.data.fil05 == 1 && res.data.isGen01 == 0){
                                laytpl($('#list_one').html()).render(data, function(html){
                                    $('#view').html(html);
                                });
                            } else{
                                laytpl($('#list_one').html()).render(data, function(html){
                                    $('#view').html(html);
                                });
                            }
                        })
                    })
                })

                function mergeResponse() {
                    // 两个请求都回调了，再显示画面
                    utill.loading.hide();
                    $('.page-fluid').removeClass('hide');

                    if (_DATA._GET_DETAIL) {
                        var getDetailData = _DATA._GET_DETAIL.data;
                        status.fil05 = utill.getQueryVariable('fil05');// 工单状态

                        // 获得状态
                        view.req({
                            url: api.host + api.gzbx.getEmployeeLead,
                            type: 'POST',
                            contentType: 'application/json',
                            data: JSON.stringify({
                                fil01: utill.getQueryVariable('fil01'),
                                gen01: getDetailData.fil08 || '',
                            })
                        }).done(function (res) {
                            _DATA._GET_STATUS = res;
                            var getStatusData = _DATA._GET_STATUS.data;
                            status.isGen01 = getStatusData ? +getStatusData.isGen01 : ''; // 领导人 0 是 1 否 

                            var _TPL = {
                                "1": function () {
                                    if (status.isGen01 == 0) {
                                        return `<button type="button" id="pz_btn" class="pass-btn btn1 layui-btn layui-btn-radius layui-btn-primary" lay-submit lay-filter="*">批准</button>
                                                <button type="button" id="th_btn" class="return-btn btn1 layui-btn layui-btn-radius layui-btn-primary">退回</button>
                                                <button type="button" class="cancel-btn btn3 layui-btn layui-btn-radius layui-btn-primary">取消</button>`
                                    } else {
                                        return `<button type="button" class="cancel-btn btn3 layui-btn layui-btn-radius layui-btn-primary">取消</button>`
                                    }
                                },
                                "2": function () {
                                    if (status.isGen01 == 0) {
                                        return `<button type="button" id="zd_btn" class="btn1 layui-btn layui-btn-radius layui-btn-primary">转单</button>
                            <button type="button" class="cancel-btn btn3 layui-btn layui-btn-radius layui-btn-primary">取消</button>`
                                    } else {
                                        return `<button type="button" id="qd_btn" class="confirm-repaired-btn btn1 layui-btn layui-btn-radius layui-btn-primary">确认维修完成</button>
                            <button type="button" id="wx_btn" class="need-outRepair-btn btn2 layui-btn layui-btn-radius layui-btn-primary">需外修</button>
                            <button type="button" class="cancel-btn btn3 layui-btn layui-btn-radius layui-btn-primary">取消</button>`
                                    }

                                },
                                "7": function () {
                                    if (status.isGen01 == 0) {
                                        return `<button type="button" id="zd_btn" class="btn1 layui-btn layui-btn-radius layui-btn-primary">转单</button>
                            <button type="button" class="cancel-btn btn3 layui-btn layui-btn-radius layui-btn-primary">取消</button>`
                                    } else {
                                        return `<button type="button" id="qd_btn" class="confirm-repaired-btn btn1 layui-btn layui-btn-radius layui-btn-primary">确认维修完成</button>
                            <button type="button" id="wx_btn" class="need-outRepair-btn btn2 layui-btn layui-btn-radius layui-btn-primary">需外修</button>
                            <button type="button" class="cancel-btn btn3 layui-btn layui-btn-radius layui-btn-primary">取消</button>`
                                    }

                                },
                                "4": function () {
                                    return `<button type="button" id="gd_btn" class="confirm-repaired-btn btn1 layui-btn layui-btn-radius layui-btn-primary">确认维修完成</button>
                        <button type="button" class="cancel-btn btn3 layui-btn layui-btn-radius layui-btn-primary">取消</button>`
                                }
                            }
                            var submitEvents = {
                                // 批准
                                '#pz_btn': function (e) {
                                    form.on('submit(*)', function(data){
                                        let res = data.field;
                                        res.fil01 =  $('#detail').find('[name="fil01"]').html()
                                         utill.loading.show();
                                        view.req({
                                            url: api.host + api.gzbx.FilFileWxUpdateStatePZ,
                                            type: 'POST',
                                            data: JSON.stringify(res),
                                            contentType: 'application/json',
                                        }).done(function (res) {
                                            utill.loading.hide();
                                            if (res.code == "0") {
                                                layer.msg(res.message)
                                                setTimeout(function () {
                                                    $('.cancel-btn').click();
                                                }, 1000)
                                            }
                                        })
                                        return false;
                                    })
                                },
                                // 退回
                                '#th_btn': function (e) {
                                    var opts = {
                                        fil01: $('#detail').find('[name="fil01"]').html(),
                                    }
                                    utill.loading.show();
                                    view.req({
                                        url: api.host + api.gzbx.FilFileWxUpdateStateTH,
                                        type: 'GET',
                                        data: opts,
                                    }).done(function (res) {
                                        utill.loading.hide();
                                        if (res.code == "0") {
                                            layer.msg(res.message)
                                            setTimeout(function () {
                                                $('.cancel-btn').click();
                                            }, 1000)
                                        }
                                    })
                                },
                                // 转单
                                '#zd_btn': function (e) {
                                    utill.fuzzmatch('#filuserText', {
                                        isShowValue: false,
                                        reqObj: {
                                            url: api.host + api.gzbx.selectFiaUser,
                                            type: 'POST'
                                        },
                                        dataTrans: function (res) {
                                            return res.data.map((item) => {
                                                return {
                                                    label: item.gen02,
                                                    value: item.gen01,
                                                    data: item
                                                }
                                            })
                                        },
                                        click: function (item) {
                                            var data = item.data;
                                            // 组装编辑数据
                                            $('#zdAlert').find('[name="filuser"]').val(item.value)
                                            $('#zdAlert').find('[name="filuserText"]').val(item.label)
                                        }
                                    });
                                    layer.open({
                                        type: 1,
                                        title: false,
                                        area: ['394px', '300px'],
                                        fixed: true,
                                        shadeClose: true,
                                        closeBtn: 0,
                                        content: laytpl($('#changeAlert').html()).render(getDetailData),
                                        success: function (layeror, index) {
                                            form.render();
                                            $('.alert-box .cancel-btn').click(function () {
                                                layer.closeAll();
                                            })
                                            form.on('submit(zd)', function (data) {
                                                var field = data.field;
                                                var fil01 = $('#detail').find('[name="fil01"]').html();

                                                var opts = {
                                                    fil01: fil01,
                                                    fil07: field.fil07,
                                                    filuser: field.filuser,
                                                }
                                                utill.loading.show();
                                                view.req({
                                                    url: api.host + api.gzbx.FilFileWxUpdateAppler,
                                                    type: 'POST',
                                                    data: JSON.stringify(opts),
                                                    contentType: 'application/json',
                                                }).done(function (res) {
                                                    utill.loading.hide();
                                                    if (res.code == "0") {
                                                        layer.msg(res.message)
                                                        setTimeout(function () {
                                                            layer.closeAll();
                                                            $('.cancel-btn').click();
                                                        }, 1000)
                                                    }
                                                })
                                                return false;
                                            })
                                        }
                                    });
                                },
                                
                                // 确认维修完成
                                '#qd_btn': function (e) {
                                    if ($('#detail').find('[name="tcBugId"]').html() == '') {
                                        layer.msg('请选择故障类型')
                                        return;
                                    }
                                    var opts = {
                                        fil01: $('#detail').find('[name="fil01"]').html(),
                                        tcReqBugId: $('#detail').find('[name="tcBugId"]').html(),
                                        tcReqDsc: $('#makeInfo').find('textarea').val(),
                                    }
                                    utill.loading.show();
                                    view.req({
                                        url: api.host + api.gzbx.FilFileWxUpdateStateQD,
                                        type: 'POST',
                                        data: JSON.stringify(opts),
                                        contentType: 'application/json',
                                    }).done(function (res) {
                                        utill.loading.hide();
                                        if (res.code == "0") {
                                            layer.msg(res.message)
                                            setTimeout(function () {
                                                $('.cancel-btn').click();
                                            }, 1000)
                                        }
                                    })
                                },
                                '#gd_btn': function (e) {
                                    var opts = {
                                        fil01: $('#detail').find('[name="fil01"]').html()
                                    }
                                    utill.loading.show();
                                    view.req({
                                        url: api.host + api.gzbx.FilFileWxUpdateStateGD,
                                        type: 'POST',
                                        data: JSON.stringify(opts),
                                        contentType: 'application/json',
                                    }).done(function (res) {
                                        utill.loading.hide();
                                        if (res.code == "0") {
                                            layer.msg(res.message)
                                            setTimeout(function () {
                                                $('.cancel-btn').click();
                                            }, 1000)
                                        }
                                    })
                                },
                                // 外修
                                '#wx_btn': function (e) {
                                    var opts = {
                                        fil01: $('#detail').find('[name="fil01"]').html(),
                                        tcReqBugId: $('#detail').find('[name="tcBugId"]').html(),
                                        tcReqDsc: $('#detail').find('[name="tcReqDsc"]').html(),
                                    }
                                    utill.loading.show();
                                    view.req({
                                        url: api.host + api.gzbx.FilFileWxUpdateStateWX,
                                        type: 'POST',
                                        data: JSON.stringify(opts),
                                        contentType: 'application/json',
                                    }).done(function (res) {
                                        utill.loading.hide();
                                        if (res.code == "0") {
                                            layer.msg(res.message)
                                            setTimeout(function () {
                                                $('.cancel-btn').click();
                                            }, 1000)
                                        }
                                    })
                                },
                            }
                            // 注册提交事件
                            for (var key in submitEvents) {
                                $('#detail .layui-btn-containner').off('click', key).on('click', key, submitEvents[key])
                            }
                            var INFO_TPL = {
                                "normal": function () {
                                    return `<li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人:<span name="filusername" data-name="filuser"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人电话:<span name="gen08w"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单时间:<span name="fil13"></span></div>
                                            </li>`
                                },
                                // 实际完工时间、处理结果、故障类型可以编辑
                                'state2': function () {
                                    return `<li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人:<span name="filusername"></span></div>
                                                <div>实际完工时间:<span id="fil15" name="fil15"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人电话:<span name="gen08w"></span></div>
                                                <div>故障类型:<span name="tcBugName"></span><span name="tcBugId" style="display: none"></span><img id="popUpType" style="width: 20px; height: 20px; cursor: pointer;position: relative;
    top: -1px;" src="../src/img/add-to-blue@2x.png" alt="" /></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单时间:<span name="fil13"></span></div>
                                            </li>
                                            <li class="pd  layui-col-sm12 layui-col-md12 layui-form">
                                                <div class="layui-form-item layui-form-text">
                                                    <label class="layui-form-label">处理结果：</label>
                                                    <div class="layui-input-block">
                                                        <textarea name="tcReqDsc" required lay-verify="required" placeholder="请输入处理结果" class="layui-textarea"></textarea>
                                                    </div>
                                            </li>`
                                },
                                'state7': function () {
                                    return `<li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人:<span name="filusername"></span></div>
                                                <div>实际完工时间:<span id="fil15" name="fil15"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人电话:<span name="gen08w"></span></div>
                                                <div>故障类型:<span name="tcBugName"></span><span name="tcBugId" style="display: none"></span><img id="popUpType" style="width: 20px; height: 20px; cursor: pointer;" src="../src/img/screening-view@2x.png" alt="" /></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单时间:<span name="fil13"></span></div>
                                            </li>
                                            <li class="pd  layui-col-sm12 layui-col-md12 layui-form">
                                                <div class="layui-form-item layui-form-text">
                                                    <label class="layui-form-label">处理结果：</label>
                                                    <div class="layui-input-block">
                                                        <textarea name="tcReqDsc" required lay-verify="required" placeholder="请输入处理结果" class="layui-textarea"></textarea>
                                                    </div>
                                            </li>`
                                },
                                // 实际完工时间、处理结果、故障类型不可编辑
                                'state4': function () {
                                    return `<li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人:<span name="filusername"></span></div>
                                                <div>实际完工时间:<span name="fil15"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人电话:<span name="gen08w"></span></div>
                                                <div>故障类型:<span name="tcBugName"></span><span name="tcBugId" style="display: none"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单时间:<span name="fil13"></span></div>
                                            </li>
                                            <li class="pd  layui-col-sm12 layui-col-md12 layui-form">
                                                <div class="layui-form-item layui-form-text">
                                                    <label class="layui-form-label">处理结果：</label>
                                                    <div class="layui-input-block">
                                                        <textarea name="tcReqDsc" placeholder="请输入处理结果" class="layui-textarea" disabled></textarea>
                                                    </div>
                                            </li>`
                                },
                                'state8': function () {
                                    return `<li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人:<span name="filusername"></span></div>
                                                <div>实际完工时间:<span name="fil15"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人电话:<span name="gen08w"></span></div>
                                                <div>故障类型:<span name="tcBugName" ></span><img style="width: 20px; height: 20px; cursor: pointer;" src="../src/img/screening-view@2x.png" alt="" /></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单时间:<span name="fil13"></span></div>
                                            </li>
                                            <li class="pd  layui-col-sm12 layui-col-md12 layui-form">
                                                <div class="layui-form-item layui-form-text">
                                                    <label class="layui-form-label">处理结果：</label>
                                                    <div class="layui-input-block">
                                                        <textarea name="tcReqDsc" placeholder="请输入处理结果" class="layui-textarea" disabled></textarea>
                                                    </div>
                                            </li>`
                                },
                                'state9': function () {
                                    return `<li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人:<span name="filusername"></span></div>
                                                <div>实际完工时间:<span name="fil15"></span></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单人电话:<span name="gen08w"></span></div>
                                                <div>故障类型:<span name="tcBugName" ></span><img style="width: 20px; height: 20px; cursor: pointer;" src="../src/img/screening-view@2x.png" alt="" /></div>
                                            </li>
                                            <li class="layui-col-sm3 layui-col-md3">
                                                <div>接单时间:<span name="fil13"></span></div>
                                            </li>
                                            <li class="pd  layui-col-sm12 layui-col-md12 layui-form">
                                                <div class="layui-form-item layui-form-text">
                                                    <label class="layui-form-label">处理结果：</label>
                                                    <div class="layui-input-block">
                                                        <textarea name="tcReqDsc" placeholder="请输入处理结果" class="layui-textarea" disabled></textarea>
                                                    </div>
                                            </li>`
                                }
                            }


                            // 0等于创建维修单
                            if (status.fil05 == 0) {
                                // 新增页面 跳转新增
                                $('#add').removeClass('hide');
                                $('#detail').addClass('hide');
                                for (var key in getDetailData) {
                                    if ($('#add').find('[name="' + key + '"]').length > 0) {
                                        var tagName = $('#add').find('[name="' + key + '"]').prop("tagName");
                                        switch (tagName) {
                                            case 'INPUT':
                                                $('#add').find('[name="' + key + '"]').val(getDetailData[key]);
                                                break;
                                            case 'TEXTAREA':
                                                $('#add').find('[name="' + key + '"]').val(getDetailData[key]);
                                                break;
                                            case 'SELECT':
                                                $('#add').find('[name="' + key + '"]').val(getDetailData[key]);
                                                break;
                                            default:
                                                $('#add').find('[name="' + key + '"]').html(getDetailData[key]);
                                                break;
                                        }
                                        form.render();
                                    }
                                }
                            } else {

                                var makeInfo = INFO_TPL['state' + status.fil05] ? INFO_TPL['state' + status.fil05]() : INFO_TPL['normal']();
                                // 根据状态显示处理信息和按钮
                                $('#detail').find('#makeInfo').html(makeInfo)
                                _TPL[status.fil05] && $('#detail').find('.layui-btn-containner').html(_TPL[status.fil05]())
                                $('.cancel-btn').attr('lay-href', 'maintain/google');
                                // 组装编辑数据
                                for (var key in getDetailData) {
                                    if ($('#detail').find('[name="' + key + '"]').length > 0) {
                                        $('#detail').find('[name="' + key + '"]').val(getDetailData[key]);
                                        $('#detail').find('[name="' + key + '"]').html(getDetailData[key]);
                                        form.render();
                                    }
                                }
                                getDetailData.tcEamFiles && $('#detail').find('[name="tcEamFiles"]').append('<span>' + getDetailData.tcEamFiles.tcFileName + '</span>')

                                // 实际完成时间组件
                                var date = new Date();
                                var nowDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes();
                                $('#fil15').html(nowDate)
                            }
                            $('#downloadFile').click(function () {
                                var local = layui.sessionData(setter.tableName);
                                var tokenName = setter.request.tokenName;
                                var token = local[tokenName];

                                var p = '?token=' + encodeURIComponent(token) + '&filePath=' + encodeURIComponent(getDetailData.tcEamFiles.tcFilePath) + '&fileName=' + encodeURIComponent(getDetailData.tcEamFiles.tcFileName);
                                var a = document.createElement('a');
                                a.href = api.host + api.gzbx.downloadFile + p;
                                a.target = '_blank';
                                a.id = 'exppub';
                                document.body.appendChild(a);
                                var alink = document.getElementById('exppub');
                                alink.click();
                                alink.parentNode.removeChild(a);
                            })

                            form.render();
                        })
                    }

                }
            };

            var add = function () {
                utill.loading.show();
                view.req({
                    url: api.host + api.gzbx.FilFileWxInsertRepairs,
                    type: 'POST'
                }).done(function (res) {
                    utill.loading.hide();
                    if (res.code == 0) {
                        var data = res.data;
                        // 组装编辑数据
                        for (var key in data) {
                            if ($('#gdInfo').find('[name="' + key + '"]').length > 0) {
                                $('#gdInfo').find('[name="' + key + '"]').val(data[key]);
                                form.render();
                            }
                        }
                    }

                })
                laydate.render({
                    elem: '#createTime'
                    , type: 'datetime'
                });
                laydate.render({
                    elem: '#happenTime'
                    , type: 'datetime'
                });
                var local = layui.sessionData(setter.tableName);
                var tokenName = setter.request.tokenName;
                var token = local[tokenName];
                var tokenObj = {};
                tokenObj[tokenName] = token;
                upload.render({
                    elem: '#updateFile'
                    , url: api.host + api.gzbx.FilFileWxReturnAccessory
                    , type: 'POST'
                    , multiple: true
                    , headers: tokenObj
                    , accept: 'file'
                    , before: function (obj) {
                        utill.loading.show();
                    }
                    , done: function (res, index, upload) {
                        if (res) { //上传成功
                            var _TPL = '';
                            res.forEach(function (item, index) {
                                _TPL = $(['<tr id="upload-' + index + '">'
                                    , '<td>' + item.tcFileName + '</td>'
                                    , '<td>'
                                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                                    , '</td>'
                                    , '</tr>'].join(''));

                                _DATA.files.push(item)
                                $('#uploadDemoView').removeClass('layui-hide');
                                $('#demoList').append(_TPL)
                            })
                            utill.loading.hide();
                            //删除
                            _TPL.find('.demo-delete').on('click', function (e) {
                                var idx = $(this).index();
                                _DATA.files.splice(idx, 1); //删除对应的文件
                                if (_DATA.files.length == 0) {
                                    $('#uploadDemoView').addClass('layui-hide');
                                }
                                _TPL.remove();
                            });
                        }
                    }
                    , error: function (index, upload) {
                    }
                });

                // 提交
                form.on('submit(saveEdit)', function (data) {
                    var baseData = data.field;
                    var opts = {
                        tcEamFile: _DATA.files
                    }
                    var val = $('input:radio[name="fil06"]:checked').val();
                    var val2 = $('input:radio[name="tcReqIsstop"]:checked').val();
                    if(val == null || val == ""){
                        layer.msg("请选择一个紧急程度");
                        return false
                    }
                    if(val2 == null || val2 == ""){
                        layer.msg("请选择一个是否停机");
                        return false
                    }
                    opts = $.extend({}, opts, baseData);
                    utill.loading.show();
                    view.req({
                        url: api.host + api.gzbx.FilFileWxInsertSubmit,
                        type: 'POST',
                        data: JSON.stringify(opts),
                        contentType: 'application/json',
                    }).done(function (res) {
                        utill.loading.hide();
                        if (res.code == "0") {
                            layer.msg(res.message)
                            setTimeout(function () {
                                $('.cancel-btn').click();
                            }, 1500)
                        }
                    })
                    return false;
                })
            }
            
            
            detail();
            if (utill.getQueryVariable('fil05') == 0) {
                add();
            }

            $('.cancel-btn').attr('lay-href', 'maintain/google');
            $('[data-jump="maintain/google"]').addClass('layui-this');


            // 设备编号
            // utill.fuzzmatch('#fil03', {
            //     isShowValue: false,
            //     reqObj: {
            //         url: api.host + api.gzbx.selectFiaDetail,
            //         type: 'POST'
            //     },
            //     dataTrans: function (res) {
            //         return res.data.map((item) => {
            //             return {
            //                 label: item.fia01,
            //                 value: item.fia01,
            //                 data: item
            //             }
            //         })
            //     },
            //     click: function (item) {
            //         var data = item.data;
            //         // 组装编辑数据
            //         for (var key in data) {
            //             if ($('#sbInfo').find('[name="' + key + '"]').length > 0) {
            //                 $('#sbInfo').find('[name="' + key + '"]').html(data[key]);
            //                 form.render();
            //             }
            //         }
            //     }
            // });
            $("#fil03").click(function(){
               layer.open({
                    type: 1,
                    title: false,
                    area: ["662px", "536px"],
                    fixed: true,
                    shadeClose: true,
                    closeBtn: 0,
                    content: $("#addDeviceTpl").html(),
                    success: alertEvent.addDevice
                });
            })
            // 故障类型事件
            $('#LAY_app_body').off('click', '#popUpType').on('click', '#popUpType', function (e) {
                var TPL = $('#deviceType').html();
                // 故障编号模糊搜索
                utill.fuzzmatch('#params', {
                    isShowValue: false,
                    reqObj: {
                        url: api.host + api.gzbx.selectBug,
                        type: 'POST'
                    },
                    dataTrans: function (res) {
                        return res.data.map((item) => {
                            return {
                                label: item.tcBugCode,
                                value: item.tcBugId,
                                data: item
                            }
                        })
                    },
                    click: function (item) {
                        var data = item.data;
                        // 组装编辑数据
                        for (var key in data) {
                            if ($('#gzType').find('[name="' + key + '"]').length > 0) {
                                $('#gzType').find('[name="' + key + '"]').html(data[key]);
                                $('#gzType').find('[name="' + key + '"]').val(data[key]);
                                form.render();
                            }
                        }
                    }
                });
                layer.open({
                    type: 1,
                    title: false,
                    area: ['394px', '320px'],
                    fixed: true,
                    shadeClose: true,
                    closeBtn: 0,
                    content: TPL,
                    success: function (layeror, index) {

                        form.render();
                        $('.alert-box .cancel-btn').click(function () {
                            layer.closeAll();
                        })
                        form.on('submit(alertConfirm)', function (data) {
                            var field = data.field;
                            $('#detail').find('[name="tcBugName"]').html(field.tcBugName)
                            $('#detail').find('[name="tcBugId"]').html(field.tcBugId)
                            setTimeout(function () {
                                layer.closeAll();
                            }, 500)
                            return false;
                        })


                    }
                });
            })
            // 事件
            var alertEvent = {
                    addDevice: function (layero, index) {
                       table.render(
                            $.extend({}, utill.tableOpts(), {
                            elem: "#MachineCapacityTable",
                            id: "#MachineCapacityTable",
                            height: 300,
                            toolbar: "",
                            url: api.host + api.gzbx.selectFiaDetail,
                            type: 'post',
                            cols: [
                                [
                                { fixed: "left", type: "radio" },
                                { field: "fia01", title: "设备编号" },
                                { field: "fic02", title: "设备类型" },
                                { field: "fii02", title: "设备型号" },
                                { field: "pmc081", title: "供应商" }
                                ]
                            ]
                        })
                      );
                    // 查询显示和隐藏
                    $('.leon-style-alert .con1').click(function(){
                      $('.con2').toggle();
                    })
                    // 条件查询
                    form.on("submit(queryTableDevice)", function (data) {
                        var allData = data.field;
                        table.reload("#MachineCapacityTable", {
                        where: allData
                        });
                        return false;
                    });
                    // 关键字查询
                    form.on("submit(queryTableDeviceHeader)", function (data) {
                        var allData2 = data.field;
                        table.reload("#MachineCapacityTable", {
                        where: allData2
                        });
                        return false;
                    });
                    // 选择一个 
                    form.on("submit(queryTableDevice2)", function (data) {
                       var res = table.checkStatus("#MachineCapacityTable").data;
                       var fia01 = res[0].fia01;
                       layer.closeAll();
                       $("#fil03").val(fia01);
                       $("#Equipment").html(res[0].fic02);
                       $("#pmc081").html(res[0].pmc081);
                       $("#fii02").html(res[0].fii02);
                       $("#tcSeriesName").html(res[0].tcSeriesName);
                       $("#tcFiaPlace").html(res[0].tcFiaPlace);
                    });
                    // 点击取消关闭
                    $(".btn2").click(function(){
                        layer.closeAll();
                    })
                   }
                }
        })

    }();
</script>

<style scoped>
    .hide {
        display: none;
    }

    .updateFileWrap {
        height: auto;
    }

    .updateFileWrap label {
        float: left;
    }

    .updateFileWrap .layui-upload-drag {
        padding: 10px;
    }

    .custom-msg {
        border-radius: 6px;
        border: 0;
        width: 250px;
    }

    .custom-msg .layui-layer-content {
        text-align: center;
    }

    .custom-msg .layui-layer-btn a {
        height: 28px;
        border-radius: 14px;
        font-size: 14px;
        line-height: 28px;
    }

    .custom-msg .layui-layer-btn a.layui-layer-btn0 {
        background: #FF4C4C;
        border: 0;
        margin-right: 50px;
    }

    #downloadFile span {
        text-decoration: underline;
        cursor: pointer;
    }
    .layui-form-radio{
        margin:0px;
    }
</style>
</body>

</html>